package org.luo.iot.domain.device;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;


import org.luo.common.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/device")
@Tag(name = "设备", description = "设备")
//@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
@Slf4j
public class DeviceController {
    @Autowired
    DeviceMapper deviceMapper;
    @Autowired
    DeviceService deviceService;

    @PostMapping
    @Operation(summary = "添加设备", description = "添加设备")
    public Result save(@RequestBody Device device){

        deviceService.save(device);
        return  Result.success(device);
    }
    @DeleteMapping("{id}")
    @Operation(summary = "删除设备", description = "删除设备")
    public Result deleteDeviceById(@PathVariable("id") int id){

        deviceService.removeById(id);
        return  Result.success();
    }
    @PutMapping()
    @Operation(summary = "修改设备", description = "修改设备")
    public Result updateDevice(@RequestBody Device device){
        deviceService.updateById(device);
        return Result.success();
    }
    
    @GetMapping("{id}")
    @Operation(summary = "设备详情", description = "设备详情")
    public Result<Device> getDeviceById(@PathVariable("id") int id){

       Device device = deviceService.getById(id);
        return  Result.success(device);
    }

    @GetMapping()
    @Operation(summary = "根据id批量查询", description = "根据id批量查询")
    public Result<List<Device>> getDeviceByIds(@RequestParam("ids") List<Integer> ids){
        List<Device> devices = deviceService.listByIds(ids);
        return  Result.success(devices);
    }

    @PutMapping("/deductPrice")
    @Operation(summary = "扣减价格", description = "扣减价格")
    public Result deductPrice(@RequestBody Device device){
        deviceService.deductPrice(device);
        return  Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查询列表", description = "查询列表")
    public Result<List<Device>> getDeviceList(DeviceQuery dq){
        List<Device> devices = deviceService.getDeviceList(dq);
        return  Result.success(devices);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询", description = "分页查询")
    public Result<Page<Device>> page(DeviceQuery dq){
        Page<Device> devices = deviceService.page(dq);
        return  Result.success(devices);
    }
}
